//
//  CNRefreshGifHeader.m
//  CsdnPlus
//
//  Created by 孟瑞瑞 on 2018/6/3.
//  Copyright © 2018年 CSDN. All rights reserved.
//

#import "CNRefreshGifHeader.h"
#import <CNBaseTool/CNCategoryHeader.h>

@implementation CNRefreshGifHeader

#pragma mark - 重写父类的方法
- (void)prepare{
    [super prepare];
    
    // 设置普通状态的动画图片
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<5; i++) {
        if ([CNThemesManager isNight])
        {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refloding%ld_b", i]];
            [idleImages addObject:image];
        }
        else
        {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refloding%ld_w", i]];
            [idleImages addObject:image];
        }
        
    }
    [self setImages:idleImages forState:MJRefreshStateIdle];
    
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<5; i++) {
        if ([CNThemesManager isNight])
        {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refloding%ld_b", i]];
            [refreshingImages addObject:image];
        }
        else
        {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refloding%ld_w", i]];
            [refreshingImages addObject:image];
        }
    }
    [self setImages:refreshingImages forState:MJRefreshStatePulling];
    
    // 设置正在刷新状态的动画图片
    [self setImages:refreshingImages forState:MJRefreshStateRefreshing];
    
    //隐藏时间
    self.lastUpdatedTimeLabel.hidden = YES;
    //隐藏状态
    self.stateLabel.hidden = YES;
//    UIView *lineView = [[UIView alloc]init];
//    lineView.theme_backgroundColor = bbsSectionLineColorPicker;
//    [self addSubview:lineView];
//    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.mas_equalTo(0);
//        make.bottom.mas_equalTo(0);
//        make.height.mas_equalTo(0.5);
//    }];
    self.theme_backgroundColor = contentPageBGColorPicker;
    
}

-(instancetype)init
{
    if (self = [super init]) {
        //监听更换皮肤通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSkin) name:CNThemeUpdateNotification object:nil];
    }
    return self;
}

#pragma mark - 公共方法

- (void)setImages:(NSArray *)images forState:(MJRefreshState)state
{
    [self setImages:images duration:0.7 forState:state];
}

-(void)changeSkin
{
    [self prepare];
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
